package com.ruoyi.car.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.car.websocket.WebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.car.domain.OrderInfo;
import com.ruoyi.car.service.IOrderInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 订单信息2Controller
 * 
 * @author ruoyi
 * @date 2024-08-21
 */
@RestController
@RequestMapping("/info")
public class OrderInfoController extends BaseController
{
    @Autowired
    private IOrderInfoService orderInfoService;


    @Autowired
    WebSocket webSocket;

    /**
     * 查询订单信息2列表
     */
    @RequiresPermissions("car:info:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderInfo orderInfo)
    {
        startPage();
        List<OrderInfo> list = orderInfoService.selectOrderInfoList(orderInfo);
        return getDataTable(list);
    }

    /**
     * 导出订单信息2列表
     */
    @RequiresPermissions("car:info:export")
    @Log(title = "订单信息2", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderInfo orderInfo)
    {
        List<OrderInfo> list = orderInfoService.selectOrderInfoList(orderInfo);
        ExcelUtil<OrderInfo> util = new ExcelUtil<OrderInfo>(OrderInfo.class);
        util.exportExcel(response, list, "订单信息2数据");
    }

    /**
     * 获取订单信息2详细信息
     */
//    @RequiresPermissions("car:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderInfoService.selectOrderInfoById(id));
    }


    @GetMapping(value = "showById/{id}")
    public AjaxResult showById(@PathVariable("id") Long id)
    {
        return success(orderInfoService.selectOrderInfoId(id));
    }

    /**
     * 新增订单信息2
     */
    @RequiresPermissions("car:info:add")
    @Log(title = "订单信息2", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.insertOrderInfo(orderInfo));
    }

    /**
     * 修改订单信息2
     */
    @RequiresPermissions("car:info:edit")
    @Log(title = "订单信息2", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.updateOrderInfo(orderInfo));
    }

    /**
     * 删除订单信息2
     */
    @RequiresPermissions("car:info:remove")
    @Log(title = "订单信息2", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderInfoService.deleteOrderInfoByIds(ids));
    }


    /**
     * @Description: 根据司机的id查询出司机的信息 然后在根据订单表的id 去查询出订单的信息
     * @Author: 李紫颖
     * @Date: 2024/8/22 8:39
     * @param id:
     * @param orderId:
     * @return: com.ruoyi.common.core.web.domain.AjaxResult
     *
     */
    @GetMapping("/showDriverById/{id}/{orderId}")
    public AjaxResult showDriverById(@PathVariable("id") Long id,
                                     @PathVariable("orderId") Long orderId){
        return success(orderInfoService.showDriverById(id,orderId));
    }




    /***
     *@Description:抢单中心
     * @return java.util.List<com.ruoyi.order.pojo.OrderInfo>
     * @author 26440
     *@date 2024/8/20 16:06
     *
     */
    @GetMapping("/getOrderInfoList")
    public List<OrderInfo> getOrderInfoList() throws JsonProcessingException {

        return orderInfoService.getOrderInfoList();

    }


    public AjaxResult getDriverOrder(){
        return orderInfoService.getDriverOrder();
    }


}
